package com.bytecodezz.app.base.framework.base.general

import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle

/**
 * @author: bytecodezz
 * @version: 1.0
 * @time: 2021/7/5 16:52
 * @package: com.bytecodezz.app.base.framework.base
 *
 * @description: Fragment基类，不建议直接基础，如果直接继承，里面过多的抽象方法需要实现
 *  主要提供的功能
 *  1、提供2中方式设置布局，按先后顺序：generateContentView返回Int、generateContentView返回View
 *  2、
 *  3、
 */
abstract class BaseFragment : Fragment(), IBaseFragment {
    val TAG = "Fragment-lifecycle"

    private var _rootView: View? = null
    val rootView: View? get() = _rootView


    override fun onAttach(context: Context) {
        super.onAttach(context)
        Log.d(TAG, "onAttach           ${this.javaClass.simpleName}||||$this ")
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d(TAG, "onCreate           ${this.javaClass.simpleName}||||$this ")
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        Log.d(TAG, "onCreateView       ${this.javaClass.simpleName}||||$this ")
        _rootView = generateContentView()?.let {
            inflater.inflate(it, container, false)
        } ?: generateContentView(inflater, container, savedInstanceState)!!
        onActionStart(rootView!!)
        return _rootView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        Log.d(TAG, "onViewCreated      ${this.javaClass.simpleName}||||$this ")
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        Log.d(TAG, "onActivityCreated  ${this.javaClass.simpleName}||||$this ")
    }

    override fun onStart() {
        super.onStart()
        Log.d(TAG, "onStart            ${this.javaClass.simpleName}||||$this ")
    }

    override fun onResume() {
        super.onResume()
        Log.d(TAG, "onResume           ${this.javaClass.simpleName}||||$this ")
    }

    override fun onPause() {
        super.onPause()
        Log.d(TAG, "onPause            ${this.javaClass.simpleName}||||$this ")
    }

    override fun onStop() {
        super.onStop()
        Log.d(TAG, "onStop             ${this.javaClass.simpleName}||||$this ")
    }

    override fun onDestroyView() {
        super.onDestroyView()
        Log.d(TAG, "onDestroyView      ${this.javaClass.simpleName}||||$this ")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "onDestroy          ${this.javaClass.simpleName}||||$this ")
    }

    override fun onDetach() {
        super.onDetach()
        Log.d(TAG, "onDetach           ${this.javaClass.simpleName}||||$this ")
    }

    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        Log.d(TAG, "onHiddenChanged  $hidden  ${this.javaClass.simpleName}||||$this ")
    }
}